package ControlLayer;

import java.sql.Date;
import java.util.ArrayList;

import DBLayer.*;
import ModelLayer.*;



public class CtrOfferMaterial {
	
	DBOfferMaterial dbOfferMaterial;
	
	public CtrOfferMaterial()
	{
		dbOfferMaterial = new DBOfferMaterial();
	}

	
	
	
	public ArrayList<OfferMaterial> getAllOfferMaterial()
	{
		return dbOfferMaterial.getAllOfferMaterials();
	}
	
	
	
	public OfferMaterial findOfferMaterial(int offerId) 
	{
		return dbOfferMaterial.findOfferMaterial(offerId);
	}	
	
	public OfferMaterial findOfferMaterialById(int offerMaterialId) 
	{
		return dbOfferMaterial.findOfferMaterialById(offerMaterialId);
	}	
	
	
	
	public int deleteOfferMaterial(int offerMaterialId)
	{
		return dbOfferMaterial.deleteOfferMaterial(offerMaterialId);
	}
	
	public int deleteOfferMaterialConnected(int offerId)
	{
		return dbOfferMaterial.deleteOfferMaterialConnected(offerId);
	}
	
	
	public int updateOfferMaterial(double price, int quantity, int orderId, String type, int materialId, String name, int offerMaterialId)
	{
		OfferMaterial offerMaterial = new OfferMaterial(price, quantity, orderId, type, materialId, name, offerMaterialId);
		return dbOfferMaterial.updateOfferMaterial(offerMaterial);
	}
	
	public void insertNewOfferMaterial(double price, int quantity, int orderId, String type, int materialId, String name, int offerMaterialId)
    {    
     OfferMaterial offerMaterialObj = new OfferMaterial();
     offerMaterialObj.setOfferId(orderId);
     offerMaterialObj.setMaterialQuantity(quantity);
     offerMaterialObj.setMaterialPrice(price);
     offerMaterialObj.setMaterialId(materialId);
     offerMaterialObj.setMaterialName(name);
     offerMaterialObj.setMaterialType(type);
     offerMaterialObj.setOfferMaterialId(offerMaterialId);
     
    

         try{
          DbConnection.startTransaction();
          
          DBOfferMaterial dbOfferMaterial = new DBOfferMaterial();
          dbOfferMaterial.insertOfferMaterial(offerMaterialObj);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	
}
